.TH std::list::push_back 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::list::push_back \- std::list::push_back

.SH Synopsis
   void push_back( const T& value ); \fB(1)\fP
   void push_back( T&& value );      \fB(2)\fP \fI(since C++11)\fP

   Appends the given element value to the end of the container.

   1) The new element is initialized as a copy of value.
   2) value is moved into the new element.

   No iterators or references are invalidated.

.SH Parameters

   value             -            the value of the element to append
.SH Type requirements
   -
   T must meet the requirements of CopyInsertable in order to use overload \fB(1)\fP.
   -
   T must meet the requirements of MoveInsertable in order to use overload \fB(2)\fP.

.SH Return value

   \fI(none)\fP

.SH Complexity

   Constant.

.SH Exceptions

   If an exception is thrown (which can be due to Allocator::allocate() or element
   copy/move constructor/assignment), this function has no effect (strong exception
   guarantee).

.SH Example


// Run this code

 #include <iomanip>
 #include <iostream>
 #include <string>
 #include <list>

 int main()
 {
     std::list<std::string> letters;

     letters.push_back("abc");
     std::string s{"def"};
     letters.push_back(std::move(s));

     std::cout << "std::list letters holds: ";
     for (auto&& e : letters)
         std::cout << std::quoted(e) << ' ';

     std::cout << "\\nMoved-from string s holds: " << std::quoted(s) << '\\n';
 }

.SH Possible output:

 std::list letters holds: "abc" "def"
 Moved-from string s holds: ""

.SH See also

   emplace_back  constructs an element in-place at the end
   \fI(C++11)\fP       \fI(public member function)\fP
   push_front    inserts an element to the beginning
                 \fI(public member function)\fP
   pop_back      removes the last element
                 \fI(public member function)\fP
   back_inserter creates a std::back_insert_iterator of type inferred from the argument
                 \fI(function template)\fP
